package interview

import (
	"github.com/lzzyuhyy/framework/mysql"
	"gorm.io/gorm"
)

// 面试题表
type Interview struct {
	gorm.Model
	CategoriesId   int    `json:"categories_id" gorm:"column:categories_id;int(11);not null;comment:面试题分类id"` //面试题分类id
	PId            int    `json:"p_id" gorm:"column:p_id;int(11);not null;comment:一级分类下的主键id"`                //一级分类下的主键id
	Status         int    `json:"status" gorm:"column:status;tinyint(1);comment:面试题状态 1.已展示 2.未展示"`           //状态
	Content        string `json:"content" gorm:"column:content;varchar(255);comment:面试题内容"`                   //面试题内容
	InterSolution  string `json:"inter_solution" gorm:"column:inter_solution;varchar(255);comment:面试题答案"`     //面试题答案
	InterviewTitle string `json:"interview_title" gorm:"column:interview_title;varchar(255);comment:面试题标题"`   //面试题标题
}

// ListInterview 首页面试题列表展示
func ListInterview(cateId int64, ids []int64) (interview []*Interview, err error) {
	err = mysql.CreateMySQLClient(func(db *gorm.DB) error {
		mysqlDb := db.Debug()
		if cateId != 0 {
			mysqlDb = mysqlDb.Where("categories_id = ?", cateId)
		}
		if len(ids) > 0 {
			mysqlDb = mysqlDb.Where("id not in(?)", ids)
		}

		return mysqlDb.Find(&interview).Error
	})
	return interview, err
}

// CreateInterview 创建面试题
func CreateInterview(c *Interview) error {
	return mysql.CreateMySQLClient(func(db *gorm.DB) error {
		return db.Create(&c).Error
	})

}
